package cn.zn.modules.budget.cur.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.zn.framework.common.utils.R;
import cn.zn.modules.budget.cur.entity.dto.BudgetInfoSumDTO;
import cn.zn.modules.budget.cur.service.TBudgetInfoService;
import cn.zn.modules.zzsys.inter.DeptInter;
import cn.zn.modules.zzsys.inter.annotation.Login;
import cn.zn.modules.zzsys.inter.annotation.LoginUser;
import cn.zn.modules.zzsys.inter.dto.LoginUserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("budget/tbudgetinfo")
public class TBudgetInfoController {
    @Autowired
    private TBudgetInfoService tBudgetInfoService;
    @Autowired
    private DeptInter deptInter;

    @GetMapping("/deptTree")
    @Login
    public List<Tree<String>> deptTree(@LoginUser LoginUserDTO loginUser) {
        if (deptInter == null) {
            return CollUtil.newArrayList();
        }
        return deptInter.deptTree(null, loginUser.getSysId());
    }

    @GetMapping("/deptTreeAll")
    public List<Tree<String>> deptTreeAll() {
        if (deptInter == null) {
            return CollUtil.newArrayList();
        }
        return deptInter.deptTree(null, null);
    }

    @PostMapping("sumList")
    public R sumList(@Valid @RequestBody BudgetInfoSumDTO budgetInfoSumDTO) {
        return R.ok().put("list", tBudgetInfoService.querySum(budgetInfoSumDTO.getDeptCode(), budgetInfoSumDTO.getProjectName(), budgetInfoSumDTO.getCateName()));
    }
}
